package cn.pzhu.pserson.service.impl;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import cn.pzhu.pserson.model.Peoplenum;
import cn.pzhu.pserson.service.IPeoplenumService;
import cn.pzhu.pserson.util.SqlUtil;
import cn.pzhu.pserson.dao.dao.PeoplenumMapper;

@Service
public class PeoplenumService implements IPeoplenumService {
    @Resource
    private PeoplenumMapper peoplenumMapper;

    @Override
    public boolean save(Peoplenum peoplenum) {
        return peoplenumMapper.insert(peoplenum) > 0;
    }

    @Override
    public boolean update(Peoplenum peoplenum) {
        return peoplenumMapper.updateByPrimaryKeySelective(peoplenum) >= 0;
    }

    @Override
    public boolean delete() {
        return peoplenumMapper.deleteByPrimaryKey() > 0;
    }


    @Override
    public Peoplenum findModel() {
        return peoplenumMapper.selectByPrimaryKey();
    }

    @Override
    public Peoplenum findModel(String[] parameters) {
        return peoplenumMapper.findModel(SqlUtil.formatParameters(parameters));
    }

    public Map<String, Object> findMap() {
        String[][] parameters = {{"wg_num", "wgNum"}, {"cy_num", "cyNum"}, {"ip", "ip"}, {"fx_num", "fxNum"}, {"pyq_num", "pyqNum"}};
        return this.findMap(parameters);
    }

    public Map<String, Object> findMap(String[][] parameters) {
        return peoplenumMapper.findMap(SqlUtil.formatParametersForAlias(parameters));
    }

    @Override
    public List<Peoplenum> loadModels() {
        return this.loadModels(null, null, null, null, -1, -1);
    }

    @Override
    public List<Peoplenum> loadModels(String condition, Object[] values, String order, String sort, int curPage, int limit) {
        return this.loadModels(null, condition, values, order, sort, curPage, limit);
    }

    @Override
    public List<Peoplenum> loadModels(String[] parameters, String condition, Object[] values, String order, String sort, int curPage, int limit) {
        return peoplenumMapper.loadModels(SqlUtil.formatParameters(parameters), SqlUtil.fillCondition(condition, values), order, sort, SqlUtil.getOffset(curPage, limit), limit);
    }

    @Override
    public List<Map<String, Object>> loadMaps() {
        String[][] parameters = {{"wg_num", "wgNum"}, {"cy_num", "cyNum"}, {"ip", "ip"}, {"fx_num", "fxNum"}, {"pyq_num", "pyqNum"}};
        return this.loadMaps(parameters, null, null, null, null, -1, -1);
    }

    @Override
    public List<Map<String, Object>> loadMaps(String condition, Object[] values, String order, String sort, int curPage, int limit) {
        String[][] parameters = {{"wg_num", "wgNum"}, {"cy_num", "cyNum"}, {"ip", "ip"}, {"fx_num", "fxNum"}, {"pyq_num", "pyqNum"}};
        return this.loadMaps(parameters, condition, values, order, sort, curPage, limit);
    }

    @Override
    public List<Map<String, Object>> loadMaps(String[][] parameters, String condition, Object[] values, String order, String sort, int curPage, int limit) {
        return peoplenumMapper.loadMaps(SqlUtil.formatParametersForAlias(parameters), SqlUtil.fillCondition(condition, values), order, sort, SqlUtil.getOffset(curPage, limit), limit);
    }

    @Override
    public long count() {
        return this.count(null, false);
    }

    @Override
    public long count(String condition, Object[] values) {
        return this.count(null, condition, values, false);
    }

    @Override
    public long count(String[] parameters, boolean isDistinct) {
        return this.count(parameters, null, null, isDistinct);
    }

    @Override
    public long count(String[] parameters, String condition, Object[] values, boolean isDistinct) {
        return peoplenumMapper.count(SqlUtil.formatParameters(parameters), SqlUtil.fillCondition(condition, values), isDistinct);
    }

}
